package demo.aj;

import demo.utils.JoinPointUtil;
import demo.utils.JedisProfilingUtil;
import redis.clients.jedis.Protocol.Command;

public aspect JedisProfilingAspect {

    pointcut Jedis2sendCommand():
      execution(redis.clients.jedis.Connection redis.clients.jedis.Connection.sendCommand(redis.clients.jedis.Protocol.Command,byte[]...));

    before():Jedis2sendCommand(){
        long start = System.currentTimeMillis();
        // System.out.println(cmd);
        JoinPointUtil.printJoinPoint(thisJoinPoint);

        JedisProfilingUtil.beforeSendCmd(thisJoinPoint);
    }

    pointcut Jedis2readProtocolWithCheckingBroken():
      call(Object redis.clients.jedis.Connection.readProtocolWithCheckingBroken());

    Object around() throws Throwable:Jedis2readProtocolWithCheckingBroken(){
        Object retVal;
        Throwable throwable = null;
        try{
            retVal = proceed();
        }catch(Throwable e){
            throw e;
        }
        JoinPointUtil.printJoinPoint(thisJoinPoint);
        JedisProfilingUtil.afterReturn(retVal);
        return retVal;
    }
}
